'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { INTEGER, STRING, DATE, TEXT } = Sequelize;
    
    await queryInterface.createTable('operation_logs', {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      user_id: {
        type: INTEGER,
        allowNull: false,
        comment: '用户ID'
      },
      user_name: {
        type: STRING(50),
        allowNull: false,
        comment: '用户姓名'
      },
      action: {
        type: STRING(100),
        allowNull: false,
        comment: '操作动作'
      },
      module: {
        type: STRING(50),
        allowNull: false,
        comment: '操作模块'
      },
      description: {
        type: STRING(200),
        allowNull: true,
        comment: '操作描述'
      },
      ip: {
        type: STRING(45),
        allowNull: true,
        comment: 'IP地址'
      },
      user_agent: {
        type: STRING(255),
        allowNull: true,
        comment: '用户代理'
      },
      request_data: {
        type: TEXT,
        allowNull: true,
        comment: '请求数据'
      },
      response_data: {
        type: TEXT,
        allowNull: true,
        comment: '响应数据'
      },
      created_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW
      },
      updated_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW
      }
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('operation_logs');
  }
};